/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package workforce.limousine.service;

import java.util.List;

import limousine.vo.Lookup;
import org.jsrpc.servlet.SessionBean;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.workforce.util.Utils;

/**
 *
 * @author krisada
 */
public class LookupManager extends SessionBean {

    private Service service = null;
    private int count = 0;
    public LookupManager() {
    }

    public void init() {
        if (service == null) {
            service = (Service) WebApplicationContextUtils.getWebApplicationContext(
                    this.getServletContext()).getBean("lookupService");
        }
    }

    public boolean remove(String id) {
        init();
        return service.remove(id);
    }

    public boolean save(Lookup lookup) {
        init();
        return service.save(lookup);
    }
    
    public int getCount(String token) {
         init();
         int crnt = service.searchCount(0, new Object[]{token});
         System.out.println("========== count:"+ crnt +" =============");
         return crnt;
    }
    

    public List<Lookup> search(int offset, String token) {
        init();
        List<Lookup> list = service.search(offset, new Object[]{token});
        return list;
    }

    public boolean update(Lookup lookup) {
        init();
        return service.update(lookup);
    }

    public Lookup findById(String id) {
        init();
        return (Lookup) service.findById(id);
    }

    public boolean removeAll(String ids[]) {
        return false;
    }

    public Service getLookupService() {
        return service;
    }

    public void setLookupService(Service lookupService) {
        this.service = lookupService;
    }
    
    public String requestId() {
        return Utils.generateId();
    }
}
